package top.songxs.gmall.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import top.songxs.gmall.cart.vo.AddCartSuccessVo;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.feign.cart.CartRpcFeignClient;

@Controller
public class CartController {

    @Autowired
    private CartRpcFeignClient cartRpcFeignClient;



    @GetMapping(value = "/addCart.html")
    public String cartIndex(@RequestParam(value = "skuId") Long skuId,
                            @RequestParam(value = "skuNum") Integer skuNum,
                            Model model
    ) {
        Result<AddCartSuccessVo> result = cartRpcFeignClient.addCart(skuId, skuNum);
        AddCartSuccessVo data = result.getData();
        model.addAttribute("skuInfo",data.getSkuInfo());
        model.addAttribute("skuNum",data.getSkuNum());
        return "cart/addCart";
    }


    @GetMapping("cart.html")
    public String toCart(){
        return "cart/index";
    }
    @GetMapping(value = "cart/deleteChecked")
    public String deleteChecked() {
        cartRpcFeignClient.deleteChecked();
        return "cart/index";
    }

}
